import 'joke.dart';

/// Exposes the state required by the UI.
class RandomJokeState {
  const RandomJokeState({
    this.joke,
    this.error,
    this.isLoading = false,
    this.isRefreshing = false,
  });

  final Joke? joke;
  final Object? error;
  final bool isLoading;
  final bool isRefreshing;

  bool get hasError => error != null;
  bool get hasJoke => joke != null;

  RandomJokeState copyWith({
    Joke? joke,
    Object? error,
    bool? isLoading,
    bool? isRefreshing,
  }) {
    return RandomJokeState(
      joke: joke ?? this.joke,
      error: error ?? this.error,
      isLoading: isLoading ?? this.isLoading,
      isRefreshing: isRefreshing ?? this.isRefreshing,
    );
  }
}
